<script setup>
import axios from "axios";
import {ref} from "vue";

const form = ref({})
//发送验证码
const sendCode = () => {
  axios.get("/api/auth/sendCode/"+form.value.phone).then(res=>{
    if (res.data.code === 200){
      alert("发送成功")
    }else {
      alert(res.data.msg)
    }
  })
}
//登录
const login = () => {
  axios.post("/api/auth/login",form.value).then(res=>{
    if (res.data.code === 200){
      alert("登录成功")
      let token = res.data.data.token;
      sessionStorage.setItem("token",token);
      location = "/shop"
    }else {
      alert(res.data.msg)
    }
  })
}
</script>

<template>
  <el-form :model="form" label-width="auto" style="max-width: 600px">
    <el-form-item label="手机号">
      <el-input v-model="form.phone" />
    </el-form-item>
    <el-form-item label="验证码">
      <el-input v-model="form.code" />
      <el-button type="primary" @click="sendCode">发送验证码</el-button>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="login">登录</el-button>
    </el-form-item>
  </el-form>
</template>

<style scoped>

</style>
